So in order to start coding my property stuff, I'm going to start out with the game manager.
So over here in the Explorer, in server script service, there's game manager.
Open that up and you'll notice that we're not requiring the property manager yet.
Let's go ahead and do that.
So I'll go to line four up here in the variable section, do a local prop MGR and now we are going to
require it.
Let's say game server script Service property manager.
Now we can call things from that module script things that aren't local to the module script.
Now let's take a look at initialize player data.
Scroll a little bit.
I left this line here in case you need to clear your data store.
Just uncomment it out.
Run the game, the data store will be cleared out, then comment it again so you don't keep clearing
it out.
All right.
Here we get our data, get async.
The call might be unsuccessful.
If it is kick the player.
We couldn't reach the data store, but it could be successful and we either have data or not have data.
If they're brand new, they don't have any data.
I just start us out with 10,000 points because we want to buy a house In your game.
You might want to make it zero.
Make them work for the points.
But if they do have data they played before, we're going to put it on their leaderboard.
We also have to do property stuff, so let's check to see if they have any property stuff.
We're going to do this data.property.
We're going to store our property stuff in property.
So if they have property, then let's take a look at our property manager and we have something like
update player with DB info.
We still have to fill that out in the property manager.
We're going to pass a player and we're going to pass the data.property, right?
So here they got property stuff down here.
They're brand new.
You can put a little note if you want, maybe a print out, print new player.
Let's go to save player data right here.
And I left a note save player property stuff.
Let's do that.
I'm going to do data.property equals.
We'll get our prop manager.
Get player items to save and we're going to need the player to get those items.
Nice.
Now go down.
Save loop is going to be identical.
We're not going to change anything.
But down here in our player added, we are going to give the player the property.
So they just got added to the game.
Let's give them some property.
If they have it, they may not have bought any.
Let's do a property manager, colon equip player.
There we go.
So I even kept that the same as in the equipment manager equip player.
You equip them with property or you equip them with weapons.
I thought it would be fine to leave it the same.
It's easier to figure out what's going on.
Now let's take a look at our property manager script.
This is a module script, so I'm in server script service over here in the Explorer.
I'm going to double click on property Manager and this is what we're requiring from the other script.
That's the table that holds the functions that we're going to use.
This is going to hold our data.
I want to define another variable for the collection of lots.
So we could have, let's say if there's six people on our server, we're going to need at least six
slots and if there's 20 people, we're going to need like 20 lots.
So I want to get a variable holding all of those lots.
So I'm going to say lot collection.
And if you'll notice here, we only have a single lot.
I think I'm going to click on Player lot over here in the Explorer right click group as model and this
is going to be my lot collection.
I'm just going to call it lots.
It's the collection of lots, so we'll have several player lots under the lots.
And then I'm going to do a workspace dot lots colon, get children and that way I'm going to have a
table for every single lot in my in my world, in my scene.
Add item to player's inventory is going to be called when we buy the lot or if we buy the house or we
make an upgrade.
Right.
We're going to get back to that.
Let's go down to equip player.
We're calling that in the game manager when we're equipping our player when he's entering the game,
let's get rid of the print statement.
We can populate this out now.
So first thing I'm going to do is check to see in our property table if the property table has a slot
for the player and if the property table slot for that player has a value.
That's true for has a lot, right?
If that is true, then we need to look in these slots, find an empty one and give it to the player.
He bought a lot.
Now he's entering the game again.
We got to give him a lot.
So I'm going to say for I and V in pairs, we're going to look through the lot collection.
Do if a lot is not owned by anybody, we're going to give it to the player entering the game.
So I'll say if not V that's the lot owner dot value than so owner value is a string value of the player's
name.
But I am going to change that.
I think I want to put the entire player in this owner tag right here.
So I'm going to right click on this owner tag and delete it.
And I'm going to put.
Another tag for object value.
I'm going to name it the exact same thing, so I'm going to name that owner.
And now I'm going to put the whole player in there, not just the name, in case I want stuff from the
player.
I can get it right from that owner tag.
Let's see.
So we'll have V that's the owner owner value.
Now nobody owns this lot, so we can put the player in that value and we're going to get the name of
the player and put it on the sign.
Right?
It said for sale, for sale sign and it was of type sign.
Let's take a look for sale sign.
There's our sign.
We have a surface guy we want that text label probably should have made those shorter names.
So we'll say surface guy text, label, text and let's put their name in there like player.name.
And you could say like player names, house or whatever you want.
This is just a string that goes right here.
Now, once we've done that, players got a lot.
We don't have to keep going through lots.
We could break out of this.
All right.
We have a few more small things in here.
This update player with DB info when the game manager reads the data for a player entering the game.
We're going to send that data here so we could use it in our module script.
Let's get our property for that player.
A property table for that player and set the data that was found in the data store.
Then while we're going to save data off either in the save loop or when they're leaving, we're going
to return the property player data.
And then down here, I have this to check to see if a player is trying to buy another lot and they already
own a lot.
So it's just a utility function, let's say if property for the player exists.
If that entry does exist, then let's check to see if the property player has a lot.
I got that right.
Has a lot.
Yeah.
There we go.
All right, So if we have the lot, then we're going to return.
True.
And else there's either no data in here for the player or we don't have the lot.
Flags switch to true.
Then we'll return a false a little bit redundant here.
Right?
Because if we have if we have property data, it's because we have a lot.
But we may want to change that.
We may want to have different types of property without a lot.
All right.
Let's go ahead and play our game, see if we have any errors in the output window.
Hit play.
And I have my view tab selected already.
Go ahead and select it.
If you don't open up the output window, check for errors.
You may have something that says like new player.
Remember we put that printout down there for new players.
I played my game since I created the data store, so I am not a new player.
All right.
I will see you in the next video and we're going to get that buying stuff going.